﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;

namespace OpenAuth.App
{
    public class BYYGH001App : ApiBaseApp<BYYGH001>
    {
        public BYYGH001App(IApiRepository<BYYGH001> repository) : base(repository)
        {
        }
       
        /// <summary>
        /// 门诊预约登记
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public IEnumerable<BYYGH001Response> PutBYYGH001(BYYGH001 model)
        {
            List<BYYGH001Response> list = new List<BYYGH001Response>();
           
            List<SqlParameter> param = new List<SqlParameter>();
            //患者id
            param.Add(new SqlParameter("@Patid", model.patid));
            //排班序号
            param.Add(new SqlParameter("@Pbxh", model.pbxh));
            //预约号序 在sql预约里面传了
            param.Add(new SqlParameter("@Yyhx","0"));
            //平台流水号
            param.Add(new SqlParameter("@Ptlsh", DateTime.Now.ToLongDateString()));
            param.Add(new SqlParameter("@Czyh", "hf001"));
            var res = Put("exec usp_web_webtrans_BYYGH001 @patid=@Patid,@pbxh=@Pbxh,@yyhx=@Yyhx,@ptlsh=@Ptlsh,@czyh=@Czyh", param);
            //返回成功结果
            if (res != null && res.Rows[0][0].ToString() == "T")
            {
                list.Add(new BYYGH001Response
                {                   
                    yyxh = res.Rows[0][1].ToString(),
                    ksdm = res.Rows[0][2].ToString(),
                    ksmc = res.Rows[0][3].ToString(),
                    ysdm = res.Rows[0][4].ToString(),
                    ysmc = res.Rows[0][5].ToString(),
                    ghrq = res.Rows[0][6].ToString(),
                    yyhx = res.Rows[0][7].ToString(),
                    ghf = res.Rows[0][8].ToString(),
                    zlf = res.Rows[0][9].ToString(),
                    ysje = res.Rows[0][10].ToString(),
                    zje = res.Rows[0][11].ToString(),
                    memo = res.Rows[0][12].ToString(),
                    yysjd = res.Rows[0][13].ToString(),
                    yysd = res.Rows[0][14].ToString(),
                    jzdz = res.Rows[0][15].ToString(),
                    yysj = res.Rows[0][16].ToString(),
                    Code = 200
                });
            }
            //返回错误结果
            else
            {
                list.Add(new BYYGH001Response { Code = 400, Message = res.Rows[0][1].ToString() });
            }
            return list.AsEnumerable<BYYGH001Response>();

        }
    }
}
